import store from "@/wlkutils/store";
import platform from "@/wlkutils/platform";
// #ifdef H5
import wxsdk from "@/wlkutils/wechat/sdk";
// #endif
export default {
    setShareInfo(scene={}) {
        const shareInfo = {
            title: "", // 分享标题
            desc: "", // 分享描述
            imageUrl: "", //分享图片
            path: "", // 分享路径
            copyLink: "", // 复制链接
            query: "", // 分享参数
        };
        const shareConfig = store.getters.initShare.content;
        const mainInfo = store.getters.initMain.content;
        shareInfo.title = scene?.title || (shareConfig && shareConfig.title) || "";
        shareInfo.imageUrl = scene?.imageUrl || (shareConfig && shareConfig.image) || "";
        shareInfo.desc = scene?.desc || "";
        shareInfo.query = this.setQuery(scene.params);
        let path = '';
        path = uni.$u.pages();
        path = path[path.length-1]?path[path.length-1].route:'';
        // #ifdef MP
        shareInfo.path = (scene?.path || path)+shareInfo.query;
        // #endif
        // #ifndef MP
        let domain = mainInfo && mainInfo.domain?mainInfo.domain:platform.host();
        shareInfo.path = (domain+(scene?.path || path))+shareInfo.query;
        // #endif
        shareInfo.copyLink = mainInfo?.domain+(scene?.path || path)+shareInfo.query;
        if (platform.get() === "wxOfficialAccount") {
            wxsdk.share.share(shareInfo);
        }
        return shareInfo;
    },
    setQuery(params={}){
        if(store.getters.isLogin){
            params.user_id = store.getters.userInfo.id;
        }
        let query = uni.$u.queryParams(params, true, 'repeat');
        return query;
    }
};
